home *** CD-ROM | disk | FTP | other *** search
- Path: news.sprintlink.net!datalytics!usenet
- From: Rob Stewart <stew@datalytics.com>
- Newsgroups: comp.lang.c++
- Subject: Re: Circular Usage (forward declaration?)
- Date: Wed, 17 Apr 1996 00:40:17 -0400
- Organization: Datalytics, Inc.
- Message-ID: <31747631.5970@datalytics.com>
- References: <MRW.96Apr16184800@tobago.siemens.ch> <ltu3ykovzc.fsf@kitz.inferenzsysteme.informatik.th-darmstadt.de>
- NNTP-Posting-Host: 204.62.224.241
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (WinNT; I)
-
- Enno Sandner wrote:
- >
- > In article <MRW.96Apr16184800@tobago.siemens.ch> mrw@tobago.siemens.ch (Waeckerlin Marc) writes:
- >
- > How do you realize this in C++:
- > (the whole problem is much more complex, but it can be reduced to that)
- >
- > class A
- > {
- > B x;
- > };
- >
- > class B
- > {
- > A x;
- > };
- >
- > There's no way -- use pointers or references instead, i.e. dynamicly
- > allocate the appropriate instance of class 'A' or class 'B'.
- >
- > Enno
-
- Enno is correct, except you also need to forward declare one of
- the classes:
-
- class B;
-
- class A
- {
- B* px;
- };
-
- class B
- {
- A x;
- };
-
- --
- Rob Stewart | My opinions are generally my own. They do
- Datalytics, Inc.| not necessarily reflect those of my employer.
-